package com.tourism.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tourism.entity.TourRoute;
import com.tourism.entity.TourRouteSpot;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.One;

import java.util.List;

@Mapper
public interface TourRouteSpotMapper extends BaseMapper<TourRouteSpot> {

    // 基础查询方法
    @Select("SELECT * FROM tour_route_spot WHERE route_id = #{routeId} ORDER BY order_num")
    List<TourRouteSpot> findByRouteId(Integer routeId);

    // 带景点信息的查询方法
    @Select("SELECT trs.*, ss.* FROM tour_route_spot trs " +
            "LEFT JOIN scenic_spot ss ON trs.spot_id = ss.id " +
            "WHERE trs.route_id = #{routeId} ORDER BY trs.order_num")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "route_id", property = "routeId"),
            @Result(column = "spot_id", property = "spotId"),
            @Result(column = "order_num", property = "orderNum"),
            @Result(column = "visit_duration", property = "visitDuration"),
            @Result(column = "description", property = "description"),
            @Result(column = "spot_id", property = "scenicSpot",
                    one = @One(select = "com.tourism.mapper.ScenicSpotMapper.selectById"))
    })
    List<TourRouteSpot> findByRouteIdWithSpot(Integer routeId);

    @Select("SELECT * FROM tour_route WHERE route_name LIKE CONCAT('%', #{routeName}, '%')")
    List<TourRoute> findByRouteName(String routeName);
}